package org.example.stream;

import org.example.entity.Hero;

import java.util.Comparator;
import java.util.stream.Stream;

public class Stream06 {
    public static void main(String[] args) {
        Stream.of(1, 2, 3, 4, 5, 1, 2, 3, 4)
                .distinct().forEach(System.out::println);
        System.out.println("-----------");
        Stream.of(
                        new Hero("独孤求败", 100),
                        new Hero("令狐冲", 90),
                        new Hero("风清扬", 98),
                        new Hero("东方不败", 98),
                        new Hero("方证", 92),
                        new Hero("任我行", 92),
                        new Hero("冲虚", 90),
                        new Hero("向问天", 88),
                        new Hero("不戒", 88)
                ).sorted((t1, t2) -> t1.getStrength() > t2.getStrength() ? -1 : t1.getStrength() == t2.getStrength() ? 0 : 1)
                .forEach(System.out::println);
        System.out.println("-----------");
        Stream.of(
                        new Hero("独孤求败", 100),
                        new Hero("令狐冲", 90),
                        new Hero("风清扬", 98),
                        new Hero("东方不败", 98),
                        new Hero("方证", 92),
                        new Hero("任我行", 92),
                        new Hero("冲虚", 90),
                        new Hero("向问天", 88),
                        new Hero("不戒", 88)
                ).sorted((t1, t2) -> Integer.compare(t2.getStrength(), t1.getStrength()))
                .forEach(System.out::println);
        System.out.println("-----------");
        Stream.of(
                        new Hero("独孤求败", 100),
                        new Hero("令狐冲", 90),
                        new Hero("风清扬", 98),
                        new Hero("东方不败", 98),
                        new Hero("方证", 92),
                        new Hero("任我行", 92),
                        new Hero("冲虚", 90),
                        new Hero("向问天", 88),
                        new Hero("不戒", 88)
                ).sorted(Comparator.comparingInt(Hero::getStrength).reversed())
                .forEach(System.out::println);
        System.out.println("-----------");
        Stream.of(
                        new Hero("独孤求败", 100),
                        new Hero("令狐冲", 90),
                        new Hero("风清扬", 98),
                        new Hero("东方不败", 98),
                        new Hero("方证", 92),
                        new Hero("任我行", 92),
                        new Hero("冲虚", 90),
                        new Hero("向问天", 88),
                        new Hero("不戒", 88)
                ).sorted(Comparator.comparingInt(Hero::getStrength).reversed().thenComparingInt(hero->hero.getName().length()))
                .forEach(System.out::println);
    }
}
